package cn.whb.hrm.interceptor;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class UserInfoInterceptor implements RequestInterceptor {

    public static final String url = "http://localhost:3010/oauth/token?client_id=system&client_secret=1&grant_type=client_credentials&redirect_uri=http://www.baidu.com";

    @Override
    public void apply(RequestTemplate requestTemplate) {
        String s = HttpUtil.get(url);
        Map<String, Object> map = JSON.parseObject(s, Map.class);
        String accessToken = map.get("access_token").toString();
        requestTemplate.header("Authorization", "bearer  " + accessToken);
    }
}
